﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;
using PopShops.Entities;

namespace PopShops
{
    public class PsContext
    {
        #region Fields

        private HttpContext context = HttpContext.Current;
        private static PsContext _current;
        private static readonly object synchro = new object();

        #endregion

        #region Ctor
        /// <summary>
        /// Creates a new instance of the PsContext class
        /// </summary>
        private PsContext()
        {
            
        }

        #endregion

        #region Properties

        public static PsContext Current
        {
            get
            {
                if (HttpContext.Current == null)
                    return null;

                if (_current == null)
                {
                    lock (synchro)
                    {
                        if (_current == null)
                            _current = new PsContext();
                    }
                }

                return _current;
            }
        }

        public object this[string key]
        {
            get
            {
                if (this.context == null)
                {
                    return null;
                }

                if (this.context.Items[key] != null)
                {
                    return this.context.Items[key];
                }
                return null;
            }
            set
            {
                if (this.context != null)
                {
                    this.context.Items.Remove(key);
                    this.context.Items.Add(key, value);

                }
            }
        }

        public string AccountKey
        {
            get
            {
                return ConfigurationManager.AppSettings["AccountKey"];
            }
        }

        public string CatalogKey
        {
            get
            {
                return ConfigurationManager.AppSettings["CatalogKey"];
            }
        }

        public string PrivateKey
        {
            get
            {
                return ConfigurationManager.AppSettings["PrivateKey"];
            }
        }

        public string Version
        {
            get
            {
                return ConfigurationManager.AppSettings["ApiVersion"];
            }
        }

        #endregion
    }
}